﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFileDialog"
#include "QMessageBox"
#include <QProcess>
#include "QDebug"



/*

单片机软件版本号：2.0   对应    qt上位机软件版本号3.7
2.0   -- 3.8
2.0   -- 3.9
*/
const QString QLabel_LED_Circle_SheetStyle_Red    = "min-width: 20px; min-height: 20px;max-width:20px; max-height: 20px;border-radius: 10px; background:red";//红色
const QString QLabel_LED_Circle_SheetStyle_Green  = "min-width: 20px; min-height: 20px;max-width:20px; max-height: 20px;border-radius: 10px; ;background:green";//绿色
const QString QLabel_LED_Circle_SheetStyle_Gray   = "min-width: 20px; min-height: 20px;max-width:20px; max-height: 20px;border-radius: 10px;  border:1px solid black;background:grey";//灰色
const QString QLabel_LED_Circle_SheetStyle_Yellow = "min-width: 20px; min-height: 20px;max-width:20px; max-height: 20px;border-radius: 10px;  border:1px solid black;background:yellow";//黄色

enum RK_Project rk_project = PROJECT;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置默认值
    int temp = 0;
    on_comboBox_2_currentIndexChanged(temp);
    ui->lineEdit_40->setText(QString::number(0));

#if UI_INCLUDE_DIO
    ui->lineEdit->setText("未打开设备！");
//    if( rk_project == PROJECT_3C )
//    {
//        on_pushButton_2_clicked();//autostart ch368
//    }

#endif
    //阈值输入浮点数限制
    float_input_restrict();

    //禁止输入
    input_restrict();

    // 默认灰色圆形警示灯
    status_led_init();

    //serial
    connect(&mSerial,SIGNAL(readyRead()),this,SLOT(on_uart_data_recive()));
    on_serversimuart_BtnRefresh_clicked();
    ui->cmb_baud->setCurrentIndex(4);

    //timer
    mTimer.setInterval(1000);
    connect(&mTimer,SIGNAL(timeout()),this,SLOT(on_timer()));
    mTimer.start(1000);
    qDebug() << QString("version:%1").arg(VERSION);
    ui->label_555->setText(QString::number(VERSION));
    if( rk_project == PROJECT_3C )
    {
        on_btn_open_clicked();      //autostart serial
    }
    if( rk_project == PROJECT_31313)
    {
        ui->label_44->setText("SW_12V  ：");
        ui->label_165->setText("SW_12V  ：");
        ui->label_11->setText("SW_12V_EN  ：");
    }
    mCycle_buf.head = 0;
    mCycle_buf.tail = 0;
    // 默认最小化
    showMinimized();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_timer()
{
    ui->lb_time->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    if( ui->btn_open->text() == "关闭串口")
    {
        if( heart_timer++ >= 30 )
        {
            //每30s发送一次心跳
            on_btn_send_heart_clicked();
            heart_timer = 0;
        }
    }
    //处理串口数据
    if( flag_uart_recive )
    {
        uart_data_handle();
        flag_uart_recive = false;
    }
#if UI_INCLUDE_DIO

    //处理DIO板卡数据
    if( flag_pcie_open )
    {
        read_pcie_io_data();
    }
#endif

    //数据状态报警
    status_call();
}

QString unsignedCharToQString(unsigned char uchar) {
    return QString(QChar(uchar));
}
#if UI_INCLUDE_DIO
void MainWindow::dio_init()
{
    ui->lineEdit_41->setText("使能");
    ui->lineEdit_46->setText("使能");
    ui->lineEdit_48->setText("使能");
    ch36x_write_mem_dword( fd, 0x24, 0x00 );
}
#endif
void MainWindow::on_btn_open_clicked()
{
    //打开串口
    if( mSerial.isOpen() == true )
    {
        mSerial.close();
        ui->btn_open->setText("打开串口");
    }
    else
    {
        if( rk_project == PROJECT_3C )
        {
#if UI_INCLUDE_DIO
            mSerial.setPortName("ttyTHS1");  //设置串口名字
#else
            mSerial.setPortName("ttyS0");  //设置串口名字
#endif

        }
        else
        {
            bool ok;
            QString portName = ui->serversimuart_CBoxSerialPort->currentText();
            int portNumber = portName.mid(3).toInt(&ok); // 提取数字部分
            if (ok && portNumber > 9) {
                portName = "\\\\.\\" + portName; // 转换为\\.\COM10格式
            }

            mSerial.setPortName( portName );  //设置串口名字

        }
        mSerial.setBaudRate(ui->cmb_baud->currentText().toUInt());

        mSerial.setReadBufferSize(30);

        //校验位（无校验）
        mSerial.setParity(QSerialPort::NoParity);

        //数据位（8）
        mSerial.setDataBits(QSerialPort::Data8);

        //停止位（1）
        mSerial.setStopBits(QSerialPort::OneStop);

        if( mSerial.open(QSerialPort::ReadWrite) )
        {
#if !(PROJECT == PROJECT_3C)
            ui->edit_recv_show->append("已经打开串口"+ui->serversimuart_CBoxSerialPort->currentText());
#endif
            ui->btn_open->setText("关闭串口");
            flag_uart_open = true;
        }
    }
}

void MainWindow::on_serversimuart_BtnRefresh_clicked()
{
    ui->serversimuart_CBoxSerialPort->clear();//清空下拉列表框内容
    QList<QSerialPortInfo> serialPortInfo = QSerialPortInfo::availablePorts();
    //在count中存储serialPortInfo的大小
    int count = serialPortInfo.count();
    //遍历这个链表,把链表中的每个元素弄进下拉列表框里
    for (int i=0;i<count ;i++ )
    {
        ui->serversimuart_CBoxSerialPort->addItem(serialPortInfo.at(i).portName());
    }
}

void MainWindow::on_uart_data_recive()
{
    QByteArray recvData = mSerial.readAll();

    unsigned char *data = reinterpret_cast<unsigned char*>(recvData.data());
    int datasize = recvData.size();

    //接收到数据，将数据插入队列
    if( mCycle_buf.head + datasize < MAX_RECV_BUF_SIZE )
    {
        memcpy( mCycle_buf.data_buf + mCycle_buf.head, data, datasize );
    }
    else if( mCycle_buf.head + datasize >= MAX_RECV_BUF_SIZE )
    {
        memcpy( mCycle_buf.data_buf + mCycle_buf.head, data, MAX_RECV_BUF_SIZE - mCycle_buf.head );
        memcpy( mCycle_buf.data_buf, mCycle_buf.data_buf + (MAX_RECV_BUF_SIZE - mCycle_buf.head), ( datasize - ( MAX_RECV_BUF_SIZE - mCycle_buf.head ) ) );
    }

    mCycle_buf.head += datasize;
    mCycle_buf.head %= MAX_RECV_BUF_SIZE;

    flag_uart_recive = 1;
}

void MainWindow::uart_data_handle()
{
    QString check;
    unsigned short pkglen = 0;
    static unsigned char workstep = 0;

    //如果队列数据为空 返回
    if( mCycle_buf.head == mCycle_buf.tail )
    {
        return;
    }
    if( workstep == 0 )
    {
        //校验帧头
        do{
            if( (mCycle_buf.data_buf[mCycle_buf.tail] == 0xAA) && ( mCycle_buf.data_buf[(mCycle_buf.tail+1)%MAX_RECV_BUF_SIZE] == 0x55 ) )
            {
                workstep = 1;
                break;
            }
            else
            {
//                qDebug() << "checkout fail！\n";

//                qDebug() << QString(" %1").arg(mCycle_buf.data_buf[mCycle_buf.tail], 2, 16, QLatin1Char('0'));
                mCycle_buf.tail++;
                mCycle_buf.tail %= MAX_RECV_BUF_SIZE;
            }
        }while( mCycle_buf.tail != mCycle_buf.head );
    }

    // package length
    if( workstep == 1 )
    {
        pkglen = mCycle_buf.data_buf[(mCycle_buf.tail+2)%MAX_RECV_BUF_SIZE];
        pkglen = pkglen * 256 + mCycle_buf.data_buf[(mCycle_buf.tail+3)%MAX_RECV_BUF_SIZE];
    }

    if( pkglen > 500 || pkglen == 0)
    {

        mCycle_buf.tail++;
        mCycle_buf.tail %= MAX_RECV_BUF_SIZE;
        workstep = 0;
        return;
    }

    if( mCycle_buf.head > mCycle_buf.tail )
    {
        if( (mCycle_buf.head - mCycle_buf.tail) < pkglen )
        {
            return;
        }
    }
    else if(mCycle_buf.head < mCycle_buf.tail)
    {
        if( ( (MAX_RECV_BUF_SIZE + mCycle_buf.head) - mCycle_buf.tail) < pkglen )
        {
            return;
        }
    }
    unsigned short sumcrc = 0;
    unsigned short reccrc = 0;

    //校验位判断
    for( int i = 0; i < pkglen - 2; i++ )
    {
        sumcrc += mCycle_buf.data_buf[(mCycle_buf.tail + i)%MAX_RECV_BUF_SIZE];
    }

    reccrc = mCycle_buf.data_buf[(mCycle_buf.tail + pkglen - 2)%MAX_RECV_BUF_SIZE];
    reccrc = reccrc * 256 + mCycle_buf.data_buf[(mCycle_buf.tail + pkglen - 1)%MAX_RECV_BUF_SIZE];
    if( sumcrc != reccrc )
    {
        mCycle_buf.tail++;
        mCycle_buf.tail %= MAX_RECV_BUF_SIZE;
        workstep = 0;
        return;
    }

    // copy data to uart_recv_buf
    memset( uart_recv_buf, 0, sizeof(uart_recv_buf));
    if( mCycle_buf.tail + pkglen < MAX_RECV_BUF_SIZE )
    {
        memcpy( uart_recv_buf, mCycle_buf.data_buf + mCycle_buf.tail, pkglen );
    }
    else if( mCycle_buf.tail + pkglen >= MAX_RECV_BUF_SIZE )
    {
        memcpy( uart_recv_buf, mCycle_buf.data_buf + mCycle_buf.tail, MAX_RECV_BUF_SIZE - mCycle_buf.tail );
        memcpy( uart_recv_buf + (MAX_RECV_BUF_SIZE - mCycle_buf.tail),  mCycle_buf.data_buf, ( pkglen - ( MAX_RECV_BUF_SIZE - mCycle_buf.tail ) ) );
    }
    mCycle_buf.tail += pkglen;
    mCycle_buf.tail %= MAX_RECV_BUF_SIZE;
    if( flag_uart_open == false )
    {
        return ;
    }

    //串口接受数据处理
    uart_data_buf_proc(uart_recv_buf + UART_DATA_HEAD_SIZE, pkglen - (UART_DATA_HEAD_SIZE + 2) );

    //在上方显示框添加显示数据
    uart_data_edit_show( uart_recv_buf, pkglen );
}

#if UI_INCLUDE_DIO
void MainWindow::read_pcie_io_data()
{
    unsigned char  mBuf[88] ="";
    unsigned int   mLen     = 0;
    unsigned short mAddr    = 0;
    uint8_t data_pos = 0;

    if(flag_pcie_open)
    {
        mLen  = 88;
        mAddr = 0x0c;
#if IS_WINDOWS
        if(!CH367mAccessBlock(mIndex,mFuncReadMemByte,&membaseaddr->mCH368MemPort[mAddr],mBuf,mLen))
#else
        uint32_t temp;
        ch36x_read_mem_dword( fd, 0X0018, &temp );
        if(ch36x_read_mem_block( fd, SIZE_DWORD,mAddr, mBuf, mLen) )
#endif
        {
//            qDebug() << "提示:MEN读取失败！\n";
            ui->lineEdit->setText("MEM读取失败！");
            new_old_abnormal_flag[35] = 1;
            ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        }

        else
        {
            //DI状态
            if(mBuf[data_pos] & 0x01) ui->lineEdit_43->setText("低");      else ui->lineEdit_43->setText("高");
            if(mBuf[data_pos] & 0x02) ui->lineEdit_45->setText("低");      else ui->lineEdit_45->setText("高");
            if(mBuf[data_pos] & 0x04) ui->lineEdit_47->setText("低");      else ui->lineEdit_47->setText("高");
            if(mBuf[data_pos] & 0x08) ui->lineEdit_49->setText("低");      else ui->lineEdit_49->setText("高");
            if(mBuf[data_pos] & 0x10) ui->lineEdit_50->setText("低");      else ui->lineEdit_50->setText("高");
            if(mBuf[data_pos] & 0x20) ui->lineEdit_51->setText("低");      else ui->lineEdit_51->setText("高");
            data_pos+=12;
            //DO输出模式
            if(mBuf[data_pos] & 0x01)
            {
                ui->lineEdit_34->setText("PWM");
                ui->gpio_DO1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                ui->pwm_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                flag_do1_mode_pwm = true;
            }
            else
            {
                ui->lineEdit_34->setText("GPIO");
                ui->gpio_DO1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                ui->pwm_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                flag_do1_mode_pwm = false;
            }
            if(mBuf[data_pos] & 0x02)
            {
                ui->lineEdit_42->setText("PWM");
                ui->gpio_DO2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                ui->pwm_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                flag_do2_mode_pwm = true;
            }
            else
            {
                ui->lineEdit_42->setText("GPIO");
                ui->gpio_DO2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                ui->pwm_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                flag_do2_mode_pwm = false;
            }
            if(mBuf[data_pos] & 0x04)
            {
                ui->lineEdit_44->setText("PWM");
                ui->gpio_DO3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                ui->pwm_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                flag_do3_mode_pwm = true;
            }
            else
            {
                ui->lineEdit_44->setText("GPIO");
                ui->gpio_DO3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
                ui->pwm_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
                flag_do3_mode_pwm = false;
            }
            data_pos+=4;
            //DO输出状态
            if( flag_do1_mode_pwm == false )
            {
                if(mBuf[data_pos] & 0x01) ui->lineEdit_37->setText("高"), ui->pushButton_3->setText("拉低");     else ui->lineEdit_37->setText("低"), ui->pushButton_3->setText("拉高");
            }

            if( flag_do2_mode_pwm == false )
            {
                if(mBuf[data_pos] & 0x02) ui->lineEdit_38->setText("高"), ui->pushButton_4->setText("拉低");     else ui->lineEdit_38->setText("低"), ui->pushButton_4->setText("拉高");
            }

            if( flag_do3_mode_pwm == false )
            {
                if(mBuf[data_pos] & 0x04) ui->lineEdit_39->setText("高"), ui->pushButton_5->setText("拉低");     else ui->lineEdit_39->setText("低"), ui->pushButton_5->setText("拉高");
            }
            data_pos+=4;

            if( flag_do1_mode_pwm == true )
            {
                if(mBuf[data_pos] & 0x01) ui->lineEdit_41->setText("使能"), ui->pushButton_7->setText("失能");     else ui->lineEdit_41->setText("未使能"), ui->pushButton_7->setText("使能");
            }
            if( flag_do2_mode_pwm == true )
            {
                if(mBuf[data_pos] & 0x02) ui->lineEdit_46->setText("使能"), ui->pushButton_8->setText("失能");     else ui->lineEdit_46->setText("未使能"), ui->pushButton_8->setText("使能");
            }
            if( flag_do3_mode_pwm == true )
            {
                if(mBuf[data_pos] & 0x04) ui->lineEdit_48->setText("使能"), ui->pushButton_9->setText("失能");     else ui->lineEdit_48->setText("未使能"), ui->pushButton_9->setText("使能");
            }
            data_pos+=4;

            //DO为pwm模式时，输出的频率和占空比
            if( flag_do1_mode_pwm == true )
            {
                uint32_t frequency_1  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
                uint32_t duty_ratio_1 = mBuf[data_pos + 7]  << 24 | mBuf[data_pos + 6]  << 16 | mBuf[data_pos + 5]  << 8 | mBuf[data_pos + 4];
                ui->lineEdit_35->setText(QString::number(frequency_1 ));
                ui->lineEdit_36->setText(QString::number(duty_ratio_1));
            }
            if( flag_do2_mode_pwm == true )
            {
                uint32_t frequency_2  = mBuf[data_pos + 11] << 24 | mBuf[data_pos + 10] << 16 | mBuf[data_pos + 9]  << 8 | mBuf[data_pos + 8];
                uint32_t duty_ratio_2 = mBuf[data_pos + 15] << 24 | mBuf[data_pos + 14] << 16 | mBuf[data_pos + 13] << 8 | mBuf[data_pos + 12];
                ui->lineEdit_52->setText(QString::number(frequency_2 ));
                ui->lineEdit_53->setText(QString::number(duty_ratio_2));
            }
            if( flag_do2_mode_pwm == true )
            {
                uint32_t frequency_3  = mBuf[data_pos + 19] << 24 | mBuf[data_pos + 18] << 16 | mBuf[data_pos + 17] << 8 | mBuf[data_pos + 16];
                uint32_t duty_ratio_3 = mBuf[data_pos + 23] << 24 | mBuf[data_pos + 22] << 16 | mBuf[data_pos + 21] << 8 | mBuf[data_pos + 20];
                ui->lineEdit_54->setText(QString::number(frequency_3 ));
                ui->lineEdit_55->setText(QString::number(duty_ratio_3));
            }
            data_pos+=24;
            data_pos+=16;


            uint32_t di0_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_0->setText(QString::number(di0_cnt));
            data_pos+=4;
            uint32_t di1_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_1->setText(QString::number(di1_cnt));
            data_pos+=4;
            uint32_t di2_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_2->setText(QString::number(di2_cnt));
            data_pos+=4;
            uint32_t di3_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_3->setText(QString::number(di3_cnt));
            data_pos+=4;
            uint32_t di4_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_4->setText(QString::number(di4_cnt));
            data_pos+=4;
            uint32_t di5_cnt  = mBuf[data_pos + 3]  << 24 | mBuf[data_pos + 2]  << 16 | mBuf[data_pos + 1]  << 8 | mBuf[data_pos + 0];
            ui->edit_cnt_5->setText(QString::number(di5_cnt));
            data_pos+=4;
        }
    }
}
#endif

void MainWindow::on_comboBox_2_currentIndexChanged(int index)
{
    switch(index)
    {
    case 0:self_id = 0x03020001;break;
    case 1:self_id = 0x04020002;break;
    case 2:self_id = 0x05020003;break;
    case 3:self_id = 0x06030004;break;
    case 4:self_id = 0x07030005;break;
    case 5:self_id = 0x08030006;break;
    default:                    break;
    }
}

void MainWindow::uart_data_edit_show( unsigned char * data, uint len )
{
    //在上方显示框添加显示数据
    QString recv_data = "";
    recv_data += QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss]:");
    for( uint i = 0; i < len; i++ )
    {
        recv_data += QString(" %1").arg(data[i], 2, 16, QLatin1Char('0'));
    }
#if !(PROJECT == PROJECT_3C)
    ui ->edit_recv_show ->append(recv_data);
#endif
}

void MainWindow::uart_data_buf_proc(unsigned char *data, unsigned short len)
{
    unsigned char  data_sub[256] = {0};
    unsigned int   target_id;
    unsigned short datapos = 0;

    target_id = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];

//    if(target_id != self_id)
//    {
//        return ;
//    }
    datapos+=8;

    while(datapos != len)
    {
        memset(data_sub, 0, 256);
        memcpy(data_sub, data+datapos, data[datapos+1]);
        switch(data[datapos])
        {
            case 0x02:
                on_btn_save_clicked();
                break;
            case 0x03:
                cpu_power_value_get( data_sub, data[datapos+1] );         //从串口数据中解析电源采集的数据并显示
                break;
            case 0x04:
                cpu_power_threshold_get( data_sub, data[datapos+1] );     //从串口数据中解析电源上下限阈值并显示
                break;
            case 0x05:
                cpu_power_status_get( data_sub, data[datapos+1] );        //从串口数据中解析电源状态并显示
                break;
            case 0x06:
                fan_power_status_get( data_sub, data[datapos+1] );        //从串口数据中解析风扇电源状态并显示
                break;
            case 0x07:
                fan_IO_input_get( data_sub, data[datapos+1] );            //从串口数据中解析风扇IO输入信息并显示
                break;
            case 0x09:
#if UI_INCLUDE_DIO
                power_adc_value_get( data_sub, data[datapos+1] );         //从串口数据中解析ADC电压信息并显示
#endif
                break;
            default:
//                qDebug() << "提示:解析串口数据异常！\n";
                return;
                break;
        }
        datapos+=data[datapos+1];
    }
}

void MainWindow::input_restrict()
{

    ui->lineEdit_1 ->setReadOnly(true);
    ui->lineEdit_2 ->setReadOnly(true);
    ui->lineEdit_3 ->setReadOnly(true);
    ui->lineEdit_4 ->setReadOnly(true);
    ui->lineEdit_5 ->setReadOnly(true);
    ui->lineEdit_6 ->setReadOnly(true);
    ui->lineEdit_7 ->setReadOnly(true);
    ui->lineEdit_8 ->setReadOnly(true);
    ui->lineEdit_9 ->setReadOnly(true);
    ui->lineEdit_10->setReadOnly(true);
    ui->lineEdit_11->setReadOnly(true);
    ui->lineEdit_12->setReadOnly(true);
    ui->lineEdit_13->setReadOnly(true);
    ui->lineEdit_14->setReadOnly(true);
    ui->lineEdit_15->setReadOnly(true);
    ui->lineEdit_16->setReadOnly(true);
    ui->lineEdit_17->setReadOnly(true);
    ui->lineEdit_18->setReadOnly(true);
    ui->lineEdit_19->setReadOnly(true);
    ui->lineEdit_20->setReadOnly(true);
    ui->lineEdit_21->setReadOnly(true);
    ui->lineEdit_22->setReadOnly(true);
    ui->lineEdit_23->setReadOnly(true);
    ui->lineEdit_24->setReadOnly(true);
    ui->lineEdit_25->setReadOnly(true);
    ui->lineEdit_26->setReadOnly(true);
    ui->lineEdit_27->setReadOnly(true);
    ui->lineEdit_28->setReadOnly(true);
    ui->lineEdit_29->setReadOnly(true);
    ui->lineEdit_30->setReadOnly(true);

    ui->lineEdit_31->setReadOnly(true);
    ui->lineEdit_32->setReadOnly(true);
    ui->lineEdit_33->setReadOnly(true);
        ui->lineEdit_40->setReadOnly(true);

#if !(PROJECT == PROJECT_3C)
    ui->edit_recv_show->setReadOnly(true);
#else

#endif
#if UI_INCLUDE_DIO
    ui->lineEdit ->setReadOnly(true);
    ui->lineEdit_56->setReadOnly(true);
    ui->lineEdit_57->setReadOnly(true);
    ui->lineEdit_58->setReadOnly(true);

    ui->lineEdit_34->setReadOnly(true);
    ui->lineEdit_37->setReadOnly(true);
    ui->lineEdit_41->setReadOnly(true);
    ui->lineEdit_42->setReadOnly(true);
    ui->lineEdit_38->setReadOnly(true);
    ui->lineEdit_46->setReadOnly(true);
    ui->lineEdit_44->setReadOnly(true);
    ui->lineEdit_49->setReadOnly(true);
    ui->lineEdit_48->setReadOnly(true);

    ui->lineEdit_43->setReadOnly(true);
    ui->lineEdit_45->setReadOnly(true);
    ui->lineEdit_47->setReadOnly(true);
    ui->lineEdit_49->setReadOnly(true);
    ui->lineEdit_50->setReadOnly(true);
    ui->lineEdit_51->setReadOnly(true);
    ui->edit_cnt_0 ->setReadOnly(true);
    ui->edit_cnt_1 ->setReadOnly(true);
    ui->edit_cnt_2 ->setReadOnly(true);
    ui->edit_cnt_3 ->setReadOnly(true);
    ui->edit_cnt_4 ->setReadOnly(true);
    ui->edit_cnt_5 ->setReadOnly(true);

#endif

}

void MainWindow::status_led_init()
{
    ui->status ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    ui->status_fan1_1_1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan2_1_2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan3_1_3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan4_1_4 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan5_2_1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan6_2_2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan7_2_3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan8_2_4 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan9_3_1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan10_3_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan11_3_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan12_3_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan13_4_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan14_4_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan15_4_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan16_4_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan17_5_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan18_5_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan19_5_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan20_5_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan21_6_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan22_6_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan23_6_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan24_6_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);

    ui->status_fan_en1  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en2  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en3  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en4  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en5  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en6  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en7  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en8  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en9  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en10 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en11 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_fan_en12 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);


    ui->status_cpu1_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu2_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu3_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu1_5v  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu2_5v  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu3_5v  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu1_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu2_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_cpu3_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_sw_5v    ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_out_24v  ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);

#if UI_INCLUDE_DIO
    ui->gpio_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->pwm_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->gpio_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->pwm_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->gpio_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->pwm_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
    ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Gray);
#endif
}

void MainWindow::float_input_restrict()
{
    QRegExp regExp1("[0-9]{1,2}[.][0-9]{0,3}");
    QRegExp regExp2("[0-9]{1,6}[.][0-9]{0,3}");
    QRegExp regExp3("[0-9]{1,3}[.][0-9]{0,3}");
    QRegExpValidator *pRegExpValidator1 = new QRegExpValidator(regExp1,this);
    QRegExpValidator *pRegExpValidator2 = new QRegExpValidator(regExp2,this);
    QRegExpValidator *pRegExpValidator3 = new QRegExpValidator(regExp3,this);

    ui->cpu_power_threshold_1 ->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_2 ->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_4 ->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_6 ->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_7 ->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_8 ->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_10->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_12->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_13->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_14->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_16->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_18->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_19->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_20->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_22->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_24->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_25->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_26->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_28->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_30->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_31->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_32->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_34->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_36->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_37->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_38->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_40->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_42->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_43->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_44->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_46->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_48->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_49->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_50->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_52->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_54->setValidator(pRegExpValidator3);
    ui->cpu_power_threshold_55->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_56->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_58->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_60->setValidator(pRegExpValidator3);

//#if !(PROJECT == PROJECT_3C)
    ui->cpu_power_threshold_61->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_62->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_64->setValidator(pRegExpValidator1);
    ui->cpu_power_threshold_66->setValidator(pRegExpValidator3);
//#endif
#if UI_INCLUDE_DIO
    ui->lineEdit_35 ->setValidator(pRegExpValidator2);
    ui->lineEdit_36 ->setValidator(pRegExpValidator2);
    ui->lineEdit_52 ->setValidator(pRegExpValidator2);
    ui->lineEdit_53 ->setValidator(pRegExpValidator2);
    ui->lineEdit_54 ->setValidator(pRegExpValidator2);
    ui->lineEdit_55 ->setValidator(pRegExpValidator2);
#endif
}

void MainWindow::status_call()
{
    for(int i = 0; i < STATUS_LED_COUNT; i++)
    {
        if((new_old_abnormal_flag_call[i] == 0) && (new_old_abnormal_flag[i] == 1))
        {
            ui->status ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            break;
        }
    }
    for(uint8_t i = 0; i < STATUS_LED_COUNT; i++)
    {
        if((new_old_abnormal_flag_last[i] == 0) && (new_old_abnormal_flag[i] == 1))
        {
            QString str = "";
            switch(i)
            {
            case 0 : str += "CPU1 12v 异常关闭\n\n";   break;
            case 1 : str += "CPU1 5v 异常关闭\n\n";    break;
            case 2 : str += "CPU1 3v3 异常关闭\n\n";   break;
            case 3 : str += "CPU2 12v 异常关闭\n\n";   break;
            case 4 : str += "CPU2 5v 异常关闭\n\n";    break;
            case 5 : str += "CPU2 3v3 异常关闭\n\n";   break;
            case 6 : str += "CPU3 12v 异常关闭\n\n";   break;
            case 7 : str += "CPU3 5v 异常关闭\n\n";    break;
            case 8 : str += "CPU3 3v3 异常关闭\n\n";   break;
            case 9 : str += "sw 5v 异常关闭\n\n";      break;
            case 10: str += "24v 异常关闭\n\n";        break;
            case 35: str += "DIO 异常   \n\n";        break;
            default:
                int a;
                a = i - 10;
                str = QString("风扇%1 异常关闭\n\n").arg(a);
                break;
            }
            str += QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
            QMessageBox* message = new QMessageBox(QMessageBox::Warning, "异常信息", str, QMessageBox::Ok);
            message->setAttribute(Qt::WA_DeleteOnClose); //关闭时删除对象
            message->setModal(false);
            message->show();
        }
    }
    memcpy(new_old_abnormal_flag_last,new_old_abnormal_flag,STATUS_LED_COUNT);
}

void MainWindow::cpu_power_value_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    float voltage;
    float electricity;
    float power;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_1->setText(QString::number(voltage    ));
    ui->lineEdit_2->setText(QString::number(electricity));
    ui->lineEdit_3->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_4->setText(QString::number(voltage    ));
    ui->lineEdit_5->setText(QString::number(electricity));
    ui->lineEdit_6->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_7->setText(QString::number(voltage    ));
    ui->lineEdit_8->setText(QString::number(electricity));
    ui->lineEdit_9->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_10->setText(QString::number(voltage    ));
    ui->lineEdit_11->setText(QString::number(electricity));
    ui->lineEdit_12->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_13->setText(QString::number(voltage    ));
    ui->lineEdit_14->setText(QString::number(electricity));
    ui->lineEdit_15->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_16->setText(QString::number(voltage    ));
    ui->lineEdit_17->setText(QString::number(electricity));
    ui->lineEdit_18->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_19->setText(QString::number(voltage    ));
    ui->lineEdit_20->setText(QString::number(electricity));
    ui->lineEdit_21->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_22->setText(QString::number(voltage    ));
    ui->lineEdit_23->setText(QString::number(electricity));
    ui->lineEdit_24->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_25->setText(QString::number(voltage    ));
    ui->lineEdit_26->setText(QString::number(electricity));
    ui->lineEdit_27->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
    ui->lineEdit_28->setText(QString::number(voltage    ));
    ui->lineEdit_29->setText(QString::number(electricity));
    ui->lineEdit_30->setText(QString::number(power      ));
    datapos += 6;

    voltage     = ( data[datapos  ]<<8 | data[datapos+1] ) * 0.001f;       //V
    electricity = ( data[datapos+2]<<8 | data[datapos+3] ) * 0.001f;       //mA
    power       = ( data[datapos+4]<<8 | data[datapos+5] ) * 0.01f ;       //mW
//#if !(PROJECT == PROJECT_3C)
    ui->lineEdit_31->setText(QString::number(voltage    ));
    ui->lineEdit_32->setText(QString::number(electricity));
    ui->lineEdit_33->setText(QString::number(power      ));
//#endif
    datapos += 6;
    if(datapos == len)
    {
//        qDebug() << "电源采集的数据获取成功！\n";
    }
}

void MainWindow::cpu_power_threshold_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    float temp;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_1->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_2->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_4->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_6->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_7->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_8->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_10->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_12->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_13->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_14->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_16->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_18->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_19->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_20->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_22->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_24->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_25->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_26->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_28->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_30->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_31->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_32->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_34->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_36->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_37->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_38->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_40->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_42->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_43->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_44->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_46->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_48->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_49->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_50->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_52->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_54->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_55->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_56->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->cpu_power_threshold_58->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
    ui->cpu_power_threshold_60->setText(QString::number(temp));
    datapos+=2;

    if( rk_project == PROJECT_3C )
    {
        datapos+=12;
    }
    else
    {
//#if !(PROJECT == PROJECT_3C)
        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
        ui->cpu_power_threshold_61->setText(QString::number(temp));
        datapos+=2;

        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
        ui->cpu_power_threshold_62->setText(QString::number(temp));
        datapos+=2;

        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
        datapos+=2;

        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
        ui->cpu_power_threshold_64->setText(QString::number(temp));
        datapos+=2;

        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
        datapos+=2;

        temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.01f;
        ui->cpu_power_threshold_66->setText(QString::number(temp));
        datapos+=2;
//#endif
    }
    if(datapos == len)
    {
//        qDebug() << "电源上下限阈值获取成功！\n";
    }
}

void MainWindow::cpu_power_status_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    unsigned char status;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu1_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v->setText("open");
        ui->button_power_en_cpu_1->setText("open");

        break;
        case 1:
        ui->status_cpu1_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v->setText("close");
        ui->button_power_en_cpu_1->setText("close");
        break;
        case 2:
        ui->status_cpu1_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[0] = 1;
        ui->button_cpu1_12v->setText("open");
        ui->button_power_en_cpu_1->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu2_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_2->setText("open");
        break;
        case 1:
        ui->status_cpu2_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_2->setText("close");
        break;
        case 2:
        ui->status_cpu2_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[1] = 1;
        ui->button_cpu1_12v_2->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu3_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_3->setText("open");
        break;
        case 1:
        ui->status_cpu3_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_3->setText("close");
        break;
        case 2:
        ui->status_cpu3_12v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[2] = 1;
        ui->button_cpu1_12v_3->setText("open");

        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu1_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_4->setText("open");
        ui->button_power_en_cpu_2->setText("open");
        break;
        case 1:
        ui->status_cpu1_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_4->setText("close");
        ui->button_power_en_cpu_2->setText("close");
        break;
        case 2:
        ui->status_cpu1_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[3] = 1;
        ui->button_power_en_cpu_2->setText("open");
        ui->button_cpu1_12v_4->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu2_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_5->setText("open");
        break;
        case 1:
        ui->status_cpu2_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_5->setText("close");
        break;
        case 2:
        ui->status_cpu2_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[4] = 1;

        ui->button_cpu1_12v_5->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu3_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_6->setText("open");
        break;
        case 1:
        ui->status_cpu3_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_6->setText("close");
        break;
        case 2:
        ui->status_cpu3_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[5] = 1;

        ui->button_cpu1_12v_6->setText("open");
        break;
        default:return;
    }

    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu1_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_7->setText("open");
        ui->button_power_en_cpu_3->setText("open");
        break;
        case 1:
        ui->status_cpu1_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_7->setText("close");
        ui->button_power_en_cpu_3->setText("close");
        break;
        case 2:
        ui->status_cpu1_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[6] = 1;

        ui->button_cpu1_12v_7->setText("open");
        ui->button_power_en_cpu_3->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu2_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_8->setText("open");
        break;
        case 1:
        ui->status_cpu2_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_8->setText("close");
        break;
        case 2:
        ui->status_cpu2_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[7] = 1;

        ui->button_cpu1_12v_8->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:
        ui->status_cpu3_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->button_cpu1_12v_9->setText("open");
        break;
        case 1:
        ui->status_cpu3_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->button_cpu1_12v_9->setText("close");
        break;
        case 2:
        ui->status_cpu3_3v3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[8] = 1;

        ui->button_cpu1_12v_9->setText("open");
        break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_31323 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:
            ui->status_sw_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
            ui->button_cpu1_12v_10->setText("open");
            break;
            case 1:
            ui->status_sw_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
            ui->button_cpu1_12v_10->setText("close");
            break;
            case 2:
            ui->status_sw_5v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[9] = 1;

            ui->button_cpu1_12v_10->setText("open");
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_31323 || rk_project == PROJECT_31313 || rk_project == PROJECT_38F2 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:
            ui->status_out_24v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
            ui->button_cpu1_12v_11->setText("open");
            break;
            case 1:
            ui->status_out_24v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
            ui->button_cpu1_12v_11->setText("close");
            break;
            case 2:
            ui->status_out_24v->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[10] = 1;

            ui->button_cpu1_12v_11->setText("open");
            break;
            default:return;
        }
    }


    datapos++;

    if(datapos == len)
    {
//        qDebug() << "电源状态获取成功！\n";
    }
}

void MainWindow::fan_power_status_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    unsigned char status;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_12->setText("open");  break;
        case 1:ui->status_fan_en1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_12->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_13->setText("open");  break;
        case 1:ui->status_fan_en2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_13->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_14->setText("open");  break;
        case 1:ui->status_fan_en3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_14->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan_en4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_15->setText("open");  break;
            case 1:ui->status_fan_en4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_15->setText("close"); break;
    //        case 2:ui->status_fan1_1_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);    if(cnt_en == cnt_en_call) status_abnormal_cnt++; break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en5->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_16->setText("open");  break;
        case 1:ui->status_fan_en5->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_16->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en6->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_17->setText("open");  break;
        case 1:ui->status_fan_en6->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_17->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en7->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_18->setText("open");  break;
        case 1:ui->status_fan_en7->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_18->setText("close"); break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan_en8->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_19->setText("open");  break;
            case 1:ui->status_fan_en8->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_19->setText("close"); break;
            default:return;
        }
    }

    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan_en9->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_20->setText("open");  break;
            case 1:ui->status_fan_en9->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_20->setText("close"); break;
    //        case 2:ui->status_fan1_1_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);    if(cnt_en == cnt_en_call) status_abnormal_cnt++; break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan_en10->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_21->setText("open");  break;
            case 1:ui->status_fan_en10->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_21->setText("close"); break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan_en11->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_22->setText("open");  break;
            case 1:ui->status_fan_en11->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_22->setText("close"); break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan_en12->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    ui->button_cpu1_12v_23->setText("open");  break;
        case 1:ui->status_fan_en12->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  ui->button_cpu1_12v_23->setText("close"); break;
        default:return;
    }
    datapos++;

    if(datapos == len)
    {
//        qDebug() << "风扇电源状态获取成功！\n";
    }
}

void MainWindow::fan_IO_input_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    unsigned char status;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan1_1_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan1_1_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan1_1_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[11] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan2_1_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan2_1_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan2_1_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[12] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan3_1_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan3_1_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan3_1_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[13] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan4_1_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan4_1_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan4_1_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[14] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan5_2_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan5_2_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan5_2_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[15] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan6_2_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan6_2_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan6_2_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[16] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan7_2_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan7_2_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan7_2_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[17] = 1;
             break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan8_2_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan8_2_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan8_2_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[18] = 1;break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan9_3_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan9_3_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan9_3_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[19] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan10_3_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan10_3_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan10_3_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[20] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan11_3_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan11_3_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan11_3_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[21] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan12_3_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan12_3_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan12_3_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[22] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan13_4_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan13_4_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan13_4_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[23] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan14_4_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan14_4_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan14_4_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[24] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan15_4_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan15_4_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan15_4_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[25] = 1;
            break;
            default:return;
        }
    }
    datapos++;



    status = data[datapos];

    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan16_4_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan16_4_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan16_4_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[26] = 1;
            break;
            default:return;
        }
    }

    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan17_5_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan17_5_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan17_5_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[27] = 1;
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan18_5_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan18_5_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan18_5_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[28] = 1;
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan19_5_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan19_5_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan19_5_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[29] = 1;
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan20_5_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan20_5_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan20_5_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[30] = 1;
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan21_6_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan21_6_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan21_6_1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[31] = 1;
             break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
        switch(status)
        {
            case 0:ui->status_fan22_6_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
            case 1:ui->status_fan22_6_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
            case 2:ui->status_fan22_6_2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
            new_old_abnormal_flag[32] = 1;
            break;
            default:return;
        }
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan23_6_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan23_6_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan23_6_3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[33] = 1;
         break;
        default:return;
    }
    datapos++;

    status = data[datapos];
    switch(status)
    {
        case 0:ui->status_fan24_6_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);    break;
        case 1:ui->status_fan24_6_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);  break;
        case 2:ui->status_fan24_6_4->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);
        new_old_abnormal_flag[34] = 1;
         break;
        default:return;
    }
    datapos++;

    if(datapos == len)
    {
//        qDebug() << "风扇IO输入信息获取成功！\n";
    }
}
#if UI_INCLUDE_DIO
void MainWindow::power_adc_value_get(unsigned char *data, unsigned char len)
{
    unsigned char datapos = 2;
    float temp;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->lineEdit_56->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->lineEdit_57->setText(QString::number(temp));
    datapos+=2;

    temp = ( data[datapos]<<8 | data[datapos+1] ) * 0.001f;
    ui->lineEdit_58->setText(QString::number(temp));
    datapos+=2;

    if(datapos == len)
    {
//        qDebug() << "风扇IO输入信息获取成功！\n";
    }
}
#endif
void MainWindow::on_btn_save_clicked()
{
    QMessageBox::warning(this, "Error Message", "马上关机，请立即保存数据！");
}
void MainWindow::on_button_power_en_cpu_1_clicked()
{
    QString str = ui->button_power_en_cpu_1->text();
    if(str == "open")
    {
        ui->button_power_en_cpu_1->setText("close");
        ui->button_cpu1_12v->setText("open");
        ui->button_cpu1_12v_2->setText("open");
        ui->button_cpu1_12v_3->setText("open");
    }
    else
    {
        ui->button_power_en_cpu_1->setText("open");
        ui->button_cpu1_12v->setText("close");
        ui->button_cpu1_12v_2->setText("close");
        ui->button_cpu1_12v_3->setText("close");


    }
    on_button_cpu1_12v_clicked();
    on_button_cpu1_12v_2_clicked();
    on_button_cpu1_12v_3_clicked();
}
void MainWindow::on_button_power_en_cpu_2_clicked()
{
    QString str = ui->button_power_en_cpu_2->text();
    if(str == "open")
    {
        ui->button_power_en_cpu_2->setText("close");
        ui->button_cpu1_12v_4->setText("open");
        ui->button_cpu1_12v_5->setText("open");
        ui->button_cpu1_12v_6->setText("open");
    }
    else
    {
        ui->button_power_en_cpu_2->setText("open");
        ui->button_cpu1_12v_4->setText("close");
        ui->button_cpu1_12v_5->setText("close");
        ui->button_cpu1_12v_6->setText("close");


    }
    on_button_cpu1_12v_4_clicked();
    on_button_cpu1_12v_5_clicked();
    on_button_cpu1_12v_6_clicked();
}

void MainWindow::on_button_power_en_cpu_3_clicked()
{
    QString str = ui->button_power_en_cpu_3->text();
    if(str == "open")
    {
        ui->button_power_en_cpu_3->setText("close");
        ui->button_cpu1_12v_7->setText("open");
        ui->button_cpu1_12v_8->setText("open");
        ui->button_cpu1_12v_9->setText("open");
    }
    else
    {
        ui->button_power_en_cpu_3->setText("open");
        ui->button_cpu1_12v_7->setText("close");
        ui->button_cpu1_12v_8->setText("close");
        ui->button_cpu1_12v_9->setText("close");


    }
    on_button_cpu1_12v_7_clicked();
    on_button_cpu1_12v_8_clicked();
    on_button_cpu1_12v_9_clicked();
}
void MainWindow::on_button_cpu1_12v_clicked()
{
    QString str = ui->button_cpu1_12v->text();
    if(str == "open")
    {
        ui->button_cpu1_12v->setText("close");
        ui->status_cpu1_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    else
    {
        ui->button_cpu1_12v->setText("open");
        ui->status_cpu1_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_2_clicked()
{
    QString str = ui->button_cpu1_12v_2->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_2->setText("close");
        ui->status_cpu2_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_2->setText("open");
        ui->status_cpu2_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_3_clicked()
{
    QString str = ui->button_cpu1_12v_3->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_3->setText("close");
        ui->status_cpu3_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_3->setText("open");
        ui->status_cpu3_12v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_4_clicked()
{
    QString str = ui->button_cpu1_12v_4->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_4->setText("close");
        ui->status_cpu1_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_4->setText("open");
        ui->status_cpu1_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_5_clicked()
{
    QString str = ui->button_cpu1_12v_5->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_5->setText("close");
        ui->status_cpu2_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    else
    {
        ui->button_cpu1_12v_5->setText("open");
        ui->status_cpu2_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_6_clicked()
{
    QString str = ui->button_cpu1_12v_6->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_6->setText("close");
        ui->status_cpu3_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_6->setText("open");
        ui->status_cpu3_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_7_clicked()
{
    QString str = ui->button_cpu1_12v_7->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_7->setText("close");
        ui->status_cpu1_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_7->setText("open");
        ui->status_cpu1_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_8_clicked()
{
    QString str = ui->button_cpu1_12v_8->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_8->setText("close");
        ui->status_cpu2_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    else
    {
        ui->button_cpu1_12v_8->setText("open");
        ui->status_cpu2_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_9_clicked()
{
    QString str = ui->button_cpu1_12v_9->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_9->setText("close");
        ui->status_cpu3_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_9->setText("open");
        ui->status_cpu3_3v3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_10_clicked()
{
    if( rk_project == PROJECT_31323 )
    {
        return ;
    }

    QString str = ui->button_cpu1_12v_10->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_10->setText("close");
        ui->status_sw_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_10->setText("open");
        ui->status_sw_5v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_11_clicked()
{
    if( rk_project == PROJECT_31323 || rk_project == PROJECT_31313  || rk_project == PROJECT_38F2)
    {
        return ;
    }
    QString str = ui->button_cpu1_12v_11->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_11->setText("close");
        ui->status_out_24v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    else
    {
        ui->button_cpu1_12v_11->setText("open");
        ui->status_out_24v ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_12_clicked()
{
    QString str = ui->button_cpu1_12v_12->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_12->setText("close");
        ui->status_fan_en1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_12->setText("open");
        ui->status_fan_en1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_13_clicked()
{
    QString str = ui->button_cpu1_12v_13->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_13->setText("close");
        ui->status_fan_en2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_13->setText("open");
        ui->status_fan_en2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_14_clicked()
{
    QString str = ui->button_cpu1_12v_14->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_14->setText("close");
        ui->status_fan_en3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_14->setText("open");
        ui->status_fan_en3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_15_clicked()
{
    QString str = ui->button_cpu1_12v_15->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_15->setText("close");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en4 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        }

    }
    else
    {
        ui->button_cpu1_12v_15->setText("open");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en4 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        }
    }
}

void MainWindow::on_button_cpu1_12v_16_clicked()
{
    QString str = ui->button_cpu1_12v_16->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_16->setText("close");
        ui->status_fan_en5 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_16->setText("open");
        ui->status_fan_en5 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_17_clicked()
{
    QString str = ui->button_cpu1_12v_17->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_17->setText("close");
        ui->status_fan_en6 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_17->setText("open");
        ui->status_fan_en6 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_18_clicked()
{
    QString str = ui->button_cpu1_12v_18->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_18->setText("close");
        ui->status_fan_en7 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_18->setText("open");
        ui->status_fan_en7 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_19_clicked()
{
    QString str = ui->button_cpu1_12v_19->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_19->setText("close");
        ui->status_fan_en8 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_19->setText("open");
        ui->status_fan_en8 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_20_clicked()
{
    QString str = ui->button_cpu1_12v_20->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_20->setText("close");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en9 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        }

    }
    else
    {
        ui->button_cpu1_12v_20->setText("open");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en9 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        }
    }
}

void MainWindow::on_button_cpu1_12v_21_clicked()
{
    QString str = ui->button_cpu1_12v_21->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_21->setText("close");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en10 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        }
    }
    else
    {
        ui->button_cpu1_12v_21->setText("open");
        if( rk_project == PROJECT_312E0 )
        {

        }
        else
        {
            ui->status_fan_en10 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        }
    }
}

void MainWindow::on_button_cpu1_12v_22_clicked()
{
    QString str = ui->button_cpu1_12v_22->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_22->setText("close");
        ui->status_fan_en11 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_22->setText("open");
        ui->status_fan_en11 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::on_button_cpu1_12v_23_clicked()
{
    QString str = ui->button_cpu1_12v_23->text();
    if(str == "open")
    {
        ui->button_cpu1_12v_23->setText("close");
        ui->status_fan_en12 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    }
    else
    {
        ui->button_cpu1_12v_23->setText("open");
        ui->status_fan_en12 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
}

void MainWindow::send_data_init()
{
    unsigned int  my_id = self_id;
    unsigned int target_id = 0x00000000;

    memset(sendbuf, 0, 256);
    sendbuf[0] = 0xAA;
    sendbuf[1] = 0x55;


    unsigned int dtval = 0;
    unsigned int tmpval = 0;
    QDateTime currentDateTime = QDateTime::currentDateTime();

    tmpval = currentDateTime.date().year() - 2000;
    dtval |= tmpval << 26;

    tmpval = currentDateTime.date().month();
    dtval |= tmpval << 22;

    tmpval = currentDateTime.date().day();
    dtval |= tmpval << 17;

    tmpval = currentDateTime.time().hour();
    dtval |= tmpval << 12;

    tmpval = currentDateTime.time().minute();
    dtval |= tmpval << 6;

    tmpval = currentDateTime.time().second();
    dtval |= tmpval;

    sendbuf[4]  = ( dtval >> 24 ) & 0xFF;
    sendbuf[5]  = ( dtval >> 16 ) & 0xFF;
    sendbuf[6]  = ( dtval >>  8 ) & 0xFF;
    sendbuf[7]  = ( dtval >>  0 ) & 0xFF;

    sendbuf[8]  = my_id >> 24;
    sendbuf[9]  = my_id >> 16;
    sendbuf[10] = my_id >> 8;
    sendbuf[11] = my_id;

    sendbuf[12] = target_id >> 24;
    sendbuf[13] = target_id >> 16;
    sendbuf[14] = target_id >> 8;
    sendbuf[15] = target_id;
}

void MainWindow::on_btn_send_heart_clicked()
{
    send_data_init();
    unsigned char sendlen = 24;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x00;
    sendbuf[17] = 6;

    sendbuf[18] = send_heart_cnt >> 24;
    sendbuf[19] = send_heart_cnt >> 16;
    sendbuf[20] = send_heart_cnt >> 8;
    sendbuf[21] = send_heart_cnt;
    send_heart_cnt++;
    ui->lineEdit_40->setText(QString::number(send_heart_cnt));
    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    if( rk_project == PROJECT_312E0 )
    {

    }
    else
    {
        mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );
    }

    //在上方显示框添加显示数据
    QString recv_data = "";
    recv_data += QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss]:");
    for( int i = 0; i < sendlen; i++ )
    {
        recv_data += QString(" %1").arg(sendbuf[i], 2, 16, QLatin1Char('0'));
    }
#if !(PROJECT == PROJECT_3C)
    ui ->edit_recv_show ->append(recv_data);
#endif
}

void MainWindow::on_btn_reset_cpu1_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 0;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );

    uart_data_edit_show( sendbuf, sendlen );
}

void MainWindow::on_btn_reset_cpu2_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 1;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );
    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}

void MainWindow::on_btn_reset_cpu3_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 2;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );

    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}

void MainWindow::on_btn_reset_cpu1_2_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 4;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );

    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}
void MainWindow::on_btn_reset_cpu1_3_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 5;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );

    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}

void MainWindow::on_btn_reset_cpu1_4_clicked()
{
    send_data_init();

    unsigned char sendlen = 21;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    sendbuf[16] = 0x01;
    sendbuf[17] = 3;

    sendbuf[18] = 1 << 6;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );

    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}
void MainWindow::on_btn_send_param_clicked()
{
    unsigned short voltage_threshold_low      = 0;
    unsigned short voltage_threshold_high     = 0;
    unsigned short electricity_threshold_low  = 0;
    unsigned short electricity_threshold_high = 0;
    unsigned short power_threshold_low        = 0;
    unsigned short power_threshold_high       = 0;

    if(flag_uart_open == true)
    {
        return ;
    }
    send_data_init();

    unsigned char sendlen = 179;

    sendbuf[2] = sendlen / 256;
    sendbuf[3] = sendlen % 256;

    /*************************************** 电源上下限阈值 ***************************************************/
    sendbuf[16] = 0x04; //type
    sendbuf[17] = 134;  //len

    voltage_threshold_low      = ui->cpu_power_threshold_1->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_2->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_4->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_6->text().toDouble() * 100;
    sendbuf[18] = voltage_threshold_low >> 8;
    sendbuf[19] = voltage_threshold_low;
    sendbuf[20] = voltage_threshold_high >> 8;
    sendbuf[21] = voltage_threshold_high;
    sendbuf[22] = electricity_threshold_low >> 8;
    sendbuf[23] = electricity_threshold_low;
    sendbuf[24] = electricity_threshold_high >> 8;
    sendbuf[25] = electricity_threshold_high;
    sendbuf[26] = power_threshold_low >> 8;
    sendbuf[27] = power_threshold_low;
    sendbuf[28] = power_threshold_high >> 8;
    sendbuf[29] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_7->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_8->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_10->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_12->text().toDouble() * 100;
    sendbuf[30] = voltage_threshold_low >> 8;
    sendbuf[31] = voltage_threshold_low;
    sendbuf[32] = voltage_threshold_high >> 8;
    sendbuf[33] = voltage_threshold_high;
    sendbuf[34] = electricity_threshold_low >> 8;
    sendbuf[35] = electricity_threshold_low;
    sendbuf[36] = electricity_threshold_high >> 8;
    sendbuf[37] = electricity_threshold_high;
    sendbuf[38] = power_threshold_low >> 8;
    sendbuf[39] = power_threshold_low;
    sendbuf[40] = power_threshold_high >> 8;
    sendbuf[41] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_13->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_14->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_16->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_18->text().toDouble() * 100;
    sendbuf[42] = voltage_threshold_low >> 8;
    sendbuf[43] = voltage_threshold_low;
    sendbuf[44] = voltage_threshold_high >> 8;
    sendbuf[45] = voltage_threshold_high;
    sendbuf[46] = electricity_threshold_low >> 8;
    sendbuf[47] = electricity_threshold_low;
    sendbuf[48] = electricity_threshold_high >> 8;
    sendbuf[49] = electricity_threshold_high;
    sendbuf[50] = power_threshold_low >> 8;
    sendbuf[51] = power_threshold_low;
    sendbuf[52] = power_threshold_high >> 8;
    sendbuf[53] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_19->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_20->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_22->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_24->text().toDouble() * 100;
    sendbuf[54] = voltage_threshold_low >> 8;
    sendbuf[55] = voltage_threshold_low;
    sendbuf[56] = voltage_threshold_high >> 8;
    sendbuf[57] = voltage_threshold_high;
    sendbuf[58] = electricity_threshold_low >> 8;
    sendbuf[59] = electricity_threshold_low;
    sendbuf[60] = electricity_threshold_high >> 8;
    sendbuf[61] = electricity_threshold_high;
    sendbuf[62] = power_threshold_low >> 8;
    sendbuf[63] = power_threshold_low;
    sendbuf[64] = power_threshold_high >> 8;
    sendbuf[65] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_25->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_26->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_28->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_30->text().toDouble() * 100;
    sendbuf[66] = voltage_threshold_low >> 8;
    sendbuf[67] = voltage_threshold_low;
    sendbuf[68] = voltage_threshold_high >> 8;
    sendbuf[69] = voltage_threshold_high;
    sendbuf[70] = electricity_threshold_low >> 8;
    sendbuf[71] = electricity_threshold_low;
    sendbuf[72] = electricity_threshold_high >> 8;
    sendbuf[73] = electricity_threshold_high;
    sendbuf[74] = power_threshold_low >> 8;
    sendbuf[75] = power_threshold_low;
    sendbuf[76] = power_threshold_high >> 8;
    sendbuf[77] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_31->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_32->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_34->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_36->text().toDouble() * 100;
    sendbuf[78] = voltage_threshold_low >> 8;
    sendbuf[79] = voltage_threshold_low;
    sendbuf[80] = voltage_threshold_high >> 8;
    sendbuf[81] = voltage_threshold_high;
    sendbuf[82] = electricity_threshold_low >> 8;
    sendbuf[83] = electricity_threshold_low;
    sendbuf[84] = electricity_threshold_high >> 8;
    sendbuf[85] = electricity_threshold_high;
    sendbuf[86] = power_threshold_low >> 8;
    sendbuf[87] = power_threshold_low;
    sendbuf[88] = power_threshold_high >> 8;
    sendbuf[89] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_37->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_38->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_40->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_42->text().toDouble() * 100;
    sendbuf[90] = voltage_threshold_low >> 8;
    sendbuf[91] = voltage_threshold_low;
    sendbuf[92] = voltage_threshold_high >> 8;
    sendbuf[93] = voltage_threshold_high;
    sendbuf[94] = electricity_threshold_low >> 8;
    sendbuf[95] = electricity_threshold_low;
    sendbuf[96] = electricity_threshold_high >> 8;
    sendbuf[97] = electricity_threshold_high;
    sendbuf[98] = power_threshold_low >> 8;
    sendbuf[99] = power_threshold_low;
    sendbuf[100] = power_threshold_high >> 8;
    sendbuf[101] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_43->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_44->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_46->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_48->text().toDouble() * 100;
    sendbuf[102] = voltage_threshold_low >> 8;
    sendbuf[103] = voltage_threshold_low;
    sendbuf[104] = voltage_threshold_high >> 8;
    sendbuf[105] = voltage_threshold_high;
    sendbuf[106] = electricity_threshold_low >> 8;
    sendbuf[107] = electricity_threshold_low;
    sendbuf[108] = electricity_threshold_high >> 8;
    sendbuf[109] = electricity_threshold_high;
    sendbuf[110] = power_threshold_low >> 8;
    sendbuf[111] = power_threshold_low;
    sendbuf[112] = power_threshold_high >> 8;
    sendbuf[113] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_49->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_50->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_52->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_54->text().toDouble() * 100;
    sendbuf[114] = voltage_threshold_low >> 8;
    sendbuf[115] = voltage_threshold_low;
    sendbuf[116] = voltage_threshold_high >> 8;
    sendbuf[117] = voltage_threshold_high;
    sendbuf[118] = electricity_threshold_low >> 8;
    sendbuf[119] = electricity_threshold_low;
    sendbuf[120] = electricity_threshold_high >> 8;
    sendbuf[121] = electricity_threshold_high;
    sendbuf[122] = power_threshold_low >> 8;
    sendbuf[123] = power_threshold_low;
    sendbuf[124] = power_threshold_high >> 8;
    sendbuf[125] = power_threshold_high;

    voltage_threshold_low      = ui->cpu_power_threshold_55->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_56->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_58->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_60->text().toDouble() * 100;
    sendbuf[126] = voltage_threshold_low >> 8;
    sendbuf[127] = voltage_threshold_low;
    sendbuf[128] = voltage_threshold_high >> 8;
    sendbuf[129] = voltage_threshold_high;
    sendbuf[130] = electricity_threshold_low >> 8;
    sendbuf[131] = electricity_threshold_low;
    sendbuf[132] = electricity_threshold_high >> 8;
    sendbuf[133] = electricity_threshold_high;
    sendbuf[134] = power_threshold_low >> 8;
    sendbuf[135] = power_threshold_low;
    sendbuf[136] = power_threshold_high >> 8;
    sendbuf[137] = power_threshold_high;

    if( rk_project == PROJECT_3C )
    {

    }
    else
    {
//#if !(PROJECT == PROJECT_3C)
    voltage_threshold_low      = ui->cpu_power_threshold_61->text().toDouble() * 1000;
    voltage_threshold_high     = ui->cpu_power_threshold_62->text().toDouble() * 1000;
    electricity_threshold_low  = 0;
    electricity_threshold_high = ui->cpu_power_threshold_64->text().toDouble() * 1000;
    power_threshold_low        = 0;
    power_threshold_high       = ui->cpu_power_threshold_66->text().toDouble() * 100;
    sendbuf[138] = voltage_threshold_low >> 8;
    sendbuf[139] = voltage_threshold_low;
    sendbuf[140] = voltage_threshold_high >> 8;
    sendbuf[141] = voltage_threshold_high;
    sendbuf[142] = electricity_threshold_low >> 8;
    sendbuf[143] = electricity_threshold_low;
    sendbuf[144] = electricity_threshold_high >> 8;
    sendbuf[145] = electricity_threshold_high;
    sendbuf[146] = power_threshold_low >> 8;
    sendbuf[147] = power_threshold_low;
    sendbuf[148] = power_threshold_high >> 8;
    sendbuf[149] = power_threshold_high;

//#endif
    }
/*************************************** 电源状态 ***************************************************/
    sendbuf[150] = 0x05; //type
    sendbuf[151] = 13;  //len

    unsigned char status;
    if(ui->button_cpu1_12v->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[152] = status;

    if(ui->button_cpu1_12v_2->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[153] = status;

    if(ui->button_cpu1_12v_3->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[154] = status;

    if(ui->button_cpu1_12v_4->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[155] = status;

    if(ui->button_cpu1_12v_5->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[156] = status;

    if(ui->button_cpu1_12v_6->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[157] = status;

    if(ui->button_cpu1_12v_7->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[158] = status;

    if(ui->button_cpu1_12v_8->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[159] = status;

    if(ui->button_cpu1_12v_9->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[160] = status;

    if(ui->button_cpu1_12v_10->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[161] = status;

    if(ui->button_cpu1_12v_11->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[162] = status;

/*************************************** 风扇电源状态 ***************************************************/
    sendbuf[163] = 0x06; //type
    sendbuf[164] = 14;  //len

    if(ui->button_cpu1_12v_12->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[165] = status;

    if(ui->button_cpu1_12v_13->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[166] = status;

    if(ui->button_cpu1_12v_14->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[167] = status;

    if(ui->button_cpu1_12v_15->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[168] = status;

    if(ui->button_cpu1_12v_16->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[169] = status;

    if(ui->button_cpu1_12v_17->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[170] = status;

    if(ui->button_cpu1_12v_18->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[171] = status;

    if(ui->button_cpu1_12v_19->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[172] = status;

    if(ui->button_cpu1_12v_20->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[173] = status;

    if(ui->button_cpu1_12v_21->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[174] = status;

    if(ui->button_cpu1_12v_22->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[175] = status;

    if(ui->button_cpu1_12v_23->text() == "open")
    {
        status = 0;
    }
    else
    {
        status = 1;
    }
    sendbuf[176] = status;

    unsigned short sumcrc = 0;
    for( int i = 0; i < sendlen - 2; i++ )
    {
        sumcrc += sendbuf[i];
    }
    sendbuf[sendlen - 2] = ( sumcrc >> 8 ) & 0xFF;
    sendbuf[sendlen - 1] = ( sumcrc >> 0 ) & 0xFF;
    mSerial.write( reinterpret_cast <char *>(sendbuf), sendlen );
    flag_uart_open = true;

    //在上方显示框添加显示数据
    uart_data_edit_show( sendbuf, sendlen );
}
void MainWindow::on_pushButton_16_clicked()
{
    flag_di_cnt_reset = true;
}

void MainWindow::on_pushButton_clicked()
{
    memcpy(new_old_abnormal_flag_call,new_old_abnormal_flag,STATUS_LED_COUNT);
    ui->status ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
}
void MainWindow::on_btn_stop_clicked()
{
    flag_uart_open = false;
}

void MainWindow::on_btn_continue_clicked()
{
    flag_uart_open = true;
}

#if UI_INCLUDE_DIO
void MainWindow::on_pushButton_3_clicked()
{

    QString str = ui->pushButton_3->text();
    if(str == "拉高")
    {
        ui->pushButton_3->setText("拉低");
        ui->lineEdit_37->setText("高");
    }
    else
    {
        ui->pushButton_3->setText("拉高");
        ui->lineEdit_37->setText("低");
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_4_clicked()
{

    QString str = ui->pushButton_4->text();
    if(str == "拉高")
    {
        ui->pushButton_4->setText("拉低");
        ui->lineEdit_38->setText("高");
    }
    else
    {
        ui->pushButton_4->setText("拉高");
        ui->lineEdit_38->setText("低");
    }

    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_5_clicked()
{

    QString str = ui->pushButton_5->text();
    if(str == "拉高")
    {
        ui->pushButton_5->setText("拉低");
        ui->lineEdit_39->setText("高");
    }
    else
    {
        ui->pushButton_5->setText("拉高");
        ui->lineEdit_39->setText("低");
    }

    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}


void MainWindow::on_pushButton_6_clicked()
{

    if(flag_pcie_open)
    {
#if IS_WINDOWS
        CH367mCloseDevice(mIndex);
#else
        ch36x_close(fd);
#endif

        ui->lineEdit->setText("已关闭设备！");
        ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        flag_pcie_open = false;
    }
}

void MainWindow::on_pushButton_10_clicked()
{

    if(ui->lineEdit_34->text() == "PWM")
    {
        ui->lineEdit_34->setText("GPIO");
        ui->gpio_DO1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->pwm_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
    else if(ui->lineEdit_34->text() == "GPIO")
    {
        ui->lineEdit_34->setText("PWM");
        ui->gpio_DO1->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->pwm_DO1 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_11_clicked()
{
    if(ui->lineEdit_42->text() == "PWM")
    {
        ui->lineEdit_42->setText("GPIO");
        ui->gpio_DO2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->pwm_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
    else if(ui->lineEdit_42->text() == "GPIO")
    {
        ui->lineEdit_42->setText("PWM");
        ui->gpio_DO2->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->pwm_DO2 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_12_clicked()
{
    if(ui->lineEdit_44->text() == "PWM")
    {
        ui->lineEdit_44->setText("GPIO");
        ui->gpio_DO3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        ui->pwm_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
    }
    else if(ui->lineEdit_44->text() == "GPIO")
    {
        ui->lineEdit_44->setText("PWM");
        ui->gpio_DO3->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        ui->pwm_DO3 ->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_7_clicked()
{
    QString str = ui->pushButton_7->text();
    if(str == "使能")
    {
        ui->pushButton_7->setText("失能");
        ui->lineEdit_41->setText("使能");
    }
    else
    {
        ui->pushButton_7->setText("使能");
        ui->lineEdit_41->setText("未使能");
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_8_clicked()
{
    QString str = ui->pushButton_8->text();
    if(str == "使能")
    {
        ui->pushButton_8->setText("失能");
        ui->lineEdit_46->setText("使能");
    }
    else
    {
        ui->pushButton_8->setText("使能");
        ui->lineEdit_46->setText("未使能");
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_9_clicked()
{
    QString str = ui->pushButton_9->text();
    if(str == "使能")
    {
        ui->pushButton_9->setText("失能");
        ui->lineEdit_48->setText("使能");
    }
    else
    {
        ui->pushButton_9->setText("使能");
        ui->lineEdit_48->setText("未使能");
    }
    ui->lineEdit->setText("按下确认设置参数后，发送参数！");
}

void MainWindow::on_pushButton_13_clicked()
{
    if(flag_pcie_open)
    {
        flag_pcie_open = false;
        ui->lineEdit->setText("暂停接收，设置参数！");
        ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Yellow);
        flag_DIO_change = 1;
    }
    else
    {
        ui->lineEdit->setText("设备未打开，无法设置参数！");
    }
}

void MainWindow::on_pushButton_14_clicked()
{
    if(flag_pcie_open)
    {
        ui->lineEdit->setText("未进入设置参数模式，设备正常工作！");
    }
    else
    {
        if(ui->lineEdit->text() == "未打开设备！" || ui->lineEdit->text() == "已关闭设备！")
        {
            return ;
        }
        if( flag_DIO_change )
        {
            flag_pcie_open = true;
            ui->lineEdit->setText("取消设置参数，设备正常工作！");
            ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
            flag_DIO_change = 0;
        }

    }
}

void MainWindow::on_pushButton_2_clicked()
{
    uint32_t mLen = 8,mAddr = 0x18;
    uchar buffer[8]={0x00,0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00 };
    if(!flag_pcie_open)
    {
        mIndex = ui->comboBox->currentIndex(); // 获得要打开的设备号

#if IS_WINDOWS
        if(CH367mOpenDevice(mIndex, FALSE, TRUE, 0x00) == INVALID_HANDLE_VALUE)
#else
        fd = ch36x_open(device);

        if (fd < 0)
#endif
        {
            new_old_abnormal_flag[35] = 1;

            ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Red);

            ui->lineEdit->setText("无法打开设备！");

            return ;
        }
    }
    ui->lineEdit->setText("已打开设备！");
    ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);

    //get membaseaddr
#if IS_WINDOWS
    CH368mGetMemBaseAddr(mIndex,&membaseaddr);
#else
    ulong membase;
    ch36x_get_memaddr(fd, &membase);
#endif

    flag_pcie_open = true;
    on_pushButton_13_clicked();
    on_pushButton_15_clicked();
}

void MainWindow::on_pushButton_15_clicked()
{
    uint32_t mLen = 40,mAddr = 0x18;
    uchar buffer[50]="";
    uint8_t bit_0, bit_1, bit_2;
    uint32_t temp;
    uint8_t data_pos = 0;

    if(ui->lineEdit_34->text() == "GPIO" ) bit_0 = 0; else bit_0 = 1;
    if(ui->lineEdit_42->text() == "GPIO" ) bit_1 = 0; else bit_1 = 1;
    if(ui->lineEdit_44->text() == "GPIO" ) bit_2 = 0; else bit_2 = 1;
    buffer[data_pos] = bit_0 | bit_1 << 1 | bit_2 << 2;
    data_pos += 4;

    if(ui->lineEdit_37->text() == "高" ) bit_0 = 1; else bit_0 = 0;
    if(ui->lineEdit_38->text() == "高" ) bit_1 = 1; else bit_1 = 0;
    if(ui->lineEdit_39->text() == "高" ) bit_2 = 1; else bit_2 = 0;
    buffer[data_pos] = bit_0 | bit_1 << 1 | bit_2 << 2;
    data_pos += 4;

    if(ui->lineEdit_41->text() == "未使能" ) bit_0 = 0; else bit_0 = 1;
    if(ui->lineEdit_46->text() == "未使能" ) bit_1 = 0; else bit_1 = 1;
    if(ui->lineEdit_48->text() == "未使能" ) bit_2 = 0; else bit_2 = 1;
    buffer[data_pos] = bit_0 | bit_1 << 1 | bit_2 << 2;
    data_pos += 4;

    temp = ui->lineEdit_35->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    temp = ui->lineEdit_36->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    temp = ui->lineEdit_52->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    temp = ui->lineEdit_53->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    temp = ui->lineEdit_54->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    temp = ui->lineEdit_55->text().toDouble();
    buffer[data_pos + 0] = temp;
    buffer[data_pos + 1] = temp >> 8;
    buffer[data_pos + 2] = temp >> 16;
    buffer[data_pos + 3] = temp >> 24;
    data_pos += 4;

    if( flag_di_cnt_reset == true )
    {
        buffer[data_pos] = 1;
        flag_di_cnt_reset = false;
    }
    else
    {
        buffer[data_pos] = 0;
    }
    if(!flag_pcie_open )
    {
        if( flag_DIO_change )
        {
#if IS_WINDOWS
            if( !CH367mAccessBlock(mIndex,mFuncWriteIoByte,&membaseaddr->mCH368MemPort[mAddr],buffer,mLen) )
#else
            ch36x_write_mem_dword( fd, 0x24, 0x00 );
            if( ch36x_write_mem_block(fd,SIZE_DWORD,mAddr,buffer,mLen) )
#endif
            {
//                qDebug() << "提示:参数设置失败！\n";
                ui->lineEdit->setText("参数设置失败！");
                return;
            }
            flag_pcie_open = true;
            ui->lineEdit->setText("参数设置成功！");
            ui->status_dev->setStyleSheet(QLabel_LED_Circle_SheetStyle_Green);
        }
        else
        {
            ui->lineEdit->setText("未打开设备，设置参数失败！");
        }

    }
    else
    {
        ui->lineEdit->setText("请点击暂停接受数据！");
    }
}
#endif














